{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "0911ecd7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.4bb9d9801a7b5ba634d07205045d4d3a.315360000.1972476421.282335-26643053', 'expires_in': 2592000, 'session_key': '9mzdCrz2b3OsUaUCJwF4e6lEK2l7JiK1vlyTi7V3oZEFo6f17cNZCM3Hnh1DmaXnkJs022KWnZ4SPb5y7P3u9Tu2JVf4Iw==', 'access_token': '24.1829304dbc8a26a3e6adb2068cec034e.2592000.1659708421.282335-26643053', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '309ae55522791ddc61b07063a173f9b3'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload={\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'TDGENiUpcYtUzBu979ej7ezt',\n",
    "    'client_secret': 'dfkACbDqN4k3Lucz7EcoXD3qq4ae591Y'\n",
    "        }\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "3ff669a3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'refresh_token': '25.4bb9d9801a7b5ba634d07205045d4d3a.315360000.1972476421.282335-26643053',\n",
       " 'expires_in': 2592000,\n",
       " 'session_key': '9mzdCrz2b3OsUaUCJwF4e6lEK2l7JiK1vlyTi7V3oZEFo6f17cNZCM3Hnh1DmaXnkJs022KWnZ4SPb5y7P3u9Tu2JVf4Iw==',\n",
       " 'access_token': '24.1829304dbc8a26a3e6adb2068cec034e.2592000.1659708421.282335-26643053',\n",
       " 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx',\n",
       " 'session_secret': '309ae55522791ddc61b07063a173f9b3'}"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "d50892c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.1829304dbc8a26a3e6adb2068cec034e.2592000.1659708421.282335-26643053'"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MJ_1AI=response.json()['access_token']\n",
    "MJ_1AI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "d225c9a7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'countryEn': 'France', 'grapeEn': '', 'grapeCn': '', 'color': '紫红色/Violet', 'regionCn': '勃艮第', 'regionEn': 'Bourgogne(Burgundy)', 'subRegionEn': 'Cote de Nuits', 'description': '这款酒呈靓丽的紫红色，具有覆盆子和矿物的风味，酒体中等，口感集中。', 'subRegionCn': '夜丘', 'classifyByColor': '红葡萄酒/Red Wine', 'wineryEn': 'Henri Jayer', 'wineryCn': '亨利·贾伊酒庄', 'classifyBySugar': '干型/Dry', 'wineNameEn': 'Henri Jayer Cros-Parantoux', 'wineNameCn': '亨利·贾伊克罗帕朗图红葡萄酒', 'tasteTemperature': '14-18℃', 'hasdetail': 1, 'countryCn': '法国'}, 'log_id': 1544688179027280673}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别—红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:\\Users\\86187\\Desktop\\4444.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.1829304dbc8a26a3e6adb2068cec034e.2592000.1659708421.282335-26643053'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "32c707bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': {'wineNameCn': '法国 拉菲 奥希耶徽纹 干红葡萄酒', 'hasdetail': 0}, 'log_id': 1544689033574487255}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "细粒度图像识别—红酒识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/redwine\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:\\Users\\86187\\Desktop\\red wine 1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.1829304dbc8a26a3e6adb2068cec034e.2592000.1659708421.282335-26643053'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6b597fee",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
